package com.ctshk.rpc.goods.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ctshk.rpc.goods.dto.CMSCommodityDTO;
import com.ctshk.rpc.goods.entity.CMSCommodity;
import com.ctshk.rpc.goods.mapper.CMSCommodityMapper;
import com.ctshk.rpc.goods.service.ICMSCommodityService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

@DubboService
public class CMSCommodityServiceImpl implements ICMSCommodityService {
    @Autowired
    CMSCommodityMapper cmsCommodityMapper;

    @Override
    public List<CMSCommodityDTO> selectCMSCommodityDTOByIds(List<Long> commodityIds) {
        // 根据ID列表获取数据列表
        QueryWrapper<CMSCommodity> qw = new QueryWrapper<>();
        qw.lambda().in(CMSCommodity::getId,commodityIds);

        List<CMSCommodity> cmsCommodities = cmsCommodityMapper.selectList(qw);
        if(cmsCommodities != null && cmsCommodities.size() > 0){
            List<CMSCommodityDTO> cmsCommodityDTOS = new ArrayList<>();
            cmsCommodities.forEach(item -> {
                CMSCommodityDTO cmsCommodityDTO = new CMSCommodityDTO();
                cmsCommodityDTOS.add(cmsCommodityDTO);
            });
            return cmsCommodityDTOS;
        }

        return new ArrayList<>();
    }
}
